package com.jiarong.controller;

import com.jiarong.domain.Account;
import com.jiarong.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author 加绒
 * @date 2021/10/29 11:12
 */
@Controller
public class AccountController {
    @Autowired
    private AccountService accountService;

    @PostMapping(value = "/save", produces = {"application/json;charset=UTF-8", "text/html;charset=UTF-8"})
    @ResponseBody
    public String save(Account account) {
        accountService.save(account);
        return "保存成功";
    }

    @GetMapping("/list")
    public ModelAndView list(ModelAndView modelAndView) {
        List<Account> accountList = accountService.showList();
        modelAndView.addObject("accountList", accountList);
        modelAndView.setViewName("accountList");
        return modelAndView;
    }
}
